package com.cracker.websocket.server.event.listener.sessionOffline;

import com.cracker.websocket.server.event.SessionOfflineEvent;
import com.cracker.websocket.server.service.ChatRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * 退出聊天室事件
 */
@Component
public class ChatRoomOffline implements ApplicationListener<SessionOfflineEvent> {
    @Autowired
    private ChatRoomService chatRoomService;

    @Override
    public void onApplicationEvent(SessionOfflineEvent sessionOfflineEvent) {
        chatRoomService.quit(sessionOfflineEvent.getSession(), sessionOfflineEvent.getUserEntity());
    }
}
